package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.ProductInfo;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.ProductInfoQueryObject;
import cn.wolfcode.crm.service.IProductInfoService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author konki
 * @time   2018年6月19日 下午7:03:47
 * @email  konki@qq.com
 * @description 
 */
@Controller
@RequestMapping("productInfo")
public class ProductInfoController {
	@Autowired
   private IProductInfoService productInfoService;

	@RequestMapping("")
	@PermissionName("车辆信息列表")
	@RequiresPermissions("productInfo:index")
	public String index(){
		return "productInfo/list";
	}

    @RequestMapping("list")
	@ResponseBody
	@PermissionName("车辆信息列表")
 	@RequiresPermissions("productInfo:list")
	public PageResult list(ProductInfoQueryObject qo){

	    return productInfoService.query(qo);
	}

	//保存
    @RequestMapping("save")
    @ResponseBody
    @PermissionName("车辆信息保存")
    @RequiresPermissions("productInfo:save")
    public JsonResult save(ProductInfo entity){
        JsonResult result = new JsonResult();
        try{
            productInfoService.insert(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.markMsg("保存失败");
        }
        return  result;
    }
	//保存
    @RequestMapping("update")
    @ResponseBody
    @PermissionName("车辆信息更新")
    @RequiresPermissions("productInfo:update")
    public JsonResult update(ProductInfo entity){
        JsonResult result = new JsonResult();
        try{
            productInfoService.updateByPrimaryKey(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.markMsg("更新失败");
        }
        return  result;
    }
    @RequestMapping("changeState")
    @ResponseBody
    @RequiresPermissions("productInfoService:changeState")
    @PermissionName("产品状态")
    public JsonResult changeState(Long id){
        JsonResult result = new JsonResult();
        try {
            productInfoService.changeState(id);
        }catch (Exception e){
            e.printStackTrace();
            result.markMsg("操作失败");
        }
        return result;
    }
    //不计免赔
    @RequestMapping("changeDeduction")
    @ResponseBody
    @RequiresPermissions("productInfoService:changeDeduction")
    @PermissionName("产品不计免赔")
    public JsonResult changeDeduction(Long id){
        JsonResult result = new JsonResult();
        try {
            productInfoService.changeDeduction(id);
        }catch (Exception e){
            e.printStackTrace();
            result.markMsg("操作失败");
        }
        return result;
    }



    @RequestMapping("selectProductList")
    @ResponseBody
    @PermissionName("保险产品信息")
    @RequiresPermissions("productInfo:list")
    public List<ProductInfo> selectProductList(Long id){
        return productInfoService.selectNameByAgencyId(id);
    }

    //根据机构查询保险产品
    @RequestMapping("queryByAgency")
    @ResponseBody
    public List<ProductInfo> queryByAgency(Long agencyId){
        return productInfoService.selectByAgencyId(agencyId);
    }


}
